package dominio;

import java.util.Locale;

import javax.swing.DefaultListModel;
import javax.swing.JRadioButtonMenuItem;

import presentacion.Messages;
import sun.awt.AppContext;

public class Util {

	public static Persona[] generaParticipantes() {
		Persona[] participantes = new Persona[8];
		participantes[0] = new Persona("Marina", "Guzmán", "Sánchez",
				"nada.png");
		participantes[1] = new Persona("Carlos", "Gutierrez", "Manjavacas",
				"nada.png");
		participantes[2] = new Persona("Rodrigo", "Romero", "Álvarez",
				"nada.png");
		participantes[3] = new Persona("Sheila", "Ballesteros", "Córdoba",
				"nada.png");
		participantes[4] = new Persona("Mario", "Cañas", "Baño", "nada.png");
		participantes[5] = new Persona("Miguel", "Moreno", "Fernández",
				"nada.png");
		participantes[6] = new Persona("María", "Silva", "Montero", "nada.png");
		participantes[7] = new Persona("Juan", "Crillos", "Miguelañez",
				"nada.png");
		return participantes;
	}

	public static Competicion[] generaCompeticiones(String tipo,
			String distancia) {
		Competicion[] competiciones = new Competicion[8];
		int i = 0;
		competiciones[0] = new Competicion("Carrera_" + i, "12:00",
				"13/05/2014",
				String.valueOf((int) (i * 10 * Math.random()) + 1) + " €",
				String.valueOf((int) (10000 * Math.random()) + 1) + " €", tipo,
				"Media", "Plaza de Mataró", "Plaza oculta", distancia);
		i++;
		competiciones[1] = new Competicion("Carrera_" + i, "17:00",
				"15/02/2014",
				String.valueOf((int) (i * 10 * Math.random()) + 1) + " €",
				String.valueOf((int) (10000 * Math.random()) + 1) + " €", tipo,
				"Fácil", "Plaza Castilla", "Calle Esperanza", distancia);
		i++;
		competiciones[2] = new Competicion("Carrera_" + i, "08:00",
				"20/12/2014",
				String.valueOf((int) (i * 10 * Math.random()) + 1) + " €",
				String.valueOf((int) (10000 * Math.random()) + 1) + " €", tipo,
				"Extrema", "Plaza de Mataró", "Plaza Constitución", distancia);
		i++;
		competiciones[3] = new Competicion("Carrera_" + i, "22:00",
				"13/01/2014",
				String.valueOf((int) (i * 10 * Math.random()) + 1) + " €",
				String.valueOf((int) (10000 * Math.random()) + 1) + " €", tipo,
				"Media", "Calle Molina", "Plaza oculta", distancia);
		i++;
		competiciones[4] = new Competicion("Carrera_" + i, "12:30",
				"27/03/2015",
				String.valueOf((int) (i * 10 * Math.random()) + 1) + " €",
				String.valueOf((int) (10000 * Math.random()) + 1) + " €", tipo,
				"Extrema", "Calle conceptión", "Calle Ramiro", distancia);
		i++;
		competiciones[5] = new Competicion("Carrera_" + i, "19:40",
				"03/11/2015",
				String.valueOf((int) (i * 10 * Math.random()) + 1) + " €",
				String.valueOf((int) (10000 * Math.random()) + 1) + " €", tipo,
				"Media", "Plaza Castilla", "Calle Esperanza", distancia);
		i++;
		competiciones[6] = new Competicion("Carrera_" + i, "09:30",
				"19/04/2015",
				String.valueOf((int) (i * 10 * Math.random()) + 1) + " €",
				String.valueOf((int) (10000 * Math.random()) + 1) + " €", tipo,
				"Fácil", "Plaza de Mataró", "Plaza Constitución", distancia);
		i++;
		competiciones[7] = new Competicion("Carrera_" + i, "11:00",
				"02/10/2015",
				String.valueOf((int) (i * 10 * Math.random()) + 1) + " €",
				String.valueOf((int) (10000 * Math.random()) + 1) + " €", tipo,
				"Fácil", "Calle Molina", "Plaza oculta", distancia);
		return competiciones;
	}

	public static void aniadeListaPersona(DefaultListModel m, Persona[] p) {
		for (int i = 0; i < p.length; i++) {
			m.addElement(p[i].getNombre() + " " + p[i].getApellido1() + " "
					+ p[i].getApellido2());
		}
	}

	public static void aniadeListaCompeticion(DefaultListModel m,
			Competicion[] c, int j, int num) {
		for (int i = j; i < num; i++) {
			m.addElement(c[i].getNombre() + " " + c[i].getHora() + " "
					+ c[i].getFecha());
		}
	}

	public static void recuperarIdioma(JRadioButtonMenuItem esp,
			JRadioButtonMenuItem en) {
		String idioma = Messages.getIdioma().toString();

		if (idioma.equals("en")) {
			en.setSelected(true);

		} else {
			esp.setSelected(true);

		}

	}

	public static void internacionalizarMensajes(String idioma) {
		if (idioma.equals("Inglés")) {
			Locale locale = new Locale("en", "US");
			Locale.setDefault(locale);
			AppContext.getAppContext().put("JComponent.defaultLocale", locale);
		}else{
			 Locale locale = new Locale("es", "ES");
			Locale.setDefault(locale);
			AppContext.getAppContext().put("JComponent.defaultLocale", locale);
		}
	}

}
